package tdd.t1;

public class ExtraFee implements Charger {

	public String name() {
		return getClass().getSimpleName();
	}

	protected int iSecondMiles;
	protected double dDaytimePricePerMileSec;
	protected double dNightPricePerMileSec;
	private final int iDaytimeStartTime = 6;
	private final int iNightStartTime = 23;
	private final double dDaytimePricePerMile = 2.5;
	private final double dNightPricePerMile = 3.0;
	protected TaxiFeeModel taxiFeeModel;
	
	/**
	 * @param taxiFeeModel
	 */
	public ExtraFee(TaxiFeeModel taxiFeeModel) {
		super();
		this.taxiFeeModel = taxiFeeModel;
	}

	ExtraFee() {
		this.iSecondMiles = 10;
		this.dDaytimePricePerMileSec = 3.5;
		this.dNightPricePerMileSec = 4.7; 
	}
	
	ExtraFee(int iSecondMiles,
    		double dDaytimePricePerMileSec,
    		double dNightPricePerMileSec) {
		this.iSecondMiles = iSecondMiles;
		this.dDaytimePricePerMileSec = dDaytimePricePerMileSec;
		this.dNightPricePerMileSec = dNightPricePerMileSec; 
		}
	
	 public double chargeBySec(double miles, double unitFeeSec, double unitFee) {
		 return  Math.ceil(miles) > this.iSecondMiles ?(Math.ceil(miles) - this.iSecondMiles) * unitFeeSec - 
				 (Math.ceil(miles)- this.iSecondMiles)*unitFee : 0;
	 }
	
	 public double chargeByTime(double miles, int time) throws Exception {
		 if(time>=this.iDaytimeStartTime &&time<this.iNightStartTime ) {
			 return this.chargeBySec(miles, this.dDaytimePricePerMileSec, this.dDaytimePricePerMile);
			 } else {
				 return this.chargeBySec(miles, this.dNightPricePerMileSec, this.dNightPricePerMile);	
			}
	 }

	 
	public double chargeByMiles(double miles) {
		return this.charge(miles, this.taxiFeeModel.pricePerMileSec, this.taxiFeeModel.pricePerMile);
	}

	private double charge(double miles, double pricePerMileSec,
			double pricePerMile) {
		return  Math.ceil(miles) > this.taxiFeeModel.secondMiles ? 
				(Math.ceil(miles) - this.taxiFeeModel.secondMiles) * (pricePerMileSec - pricePerMile) : 0;
	}
}
